package com.cloudoer.blog.controller;

import com.cloudoer.blog.base.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

@Controller
public class IndexController extends BaseController {
    @RequestMapping(value = "/loginUI")
    public String loginUI (){
        return "login";
    }

    @RequestMapping(value = "/index")
    public String index (){
        return "index";
    }

    @RequestMapping(value = "/exit")
    public String exit (HttpServletRequest request){
        request.getSession().invalidate();
        return "redirect:/loginUI";
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String login (String username, String password, HttpServletRequest request){
        if ("cloudoer".equals(username) && "abc159357".equals(password)){
            request.getSession().setAttribute("login", true);
            return "redirect:/index";
        }else {
            return "redirect:/loginUI";
        }
    }
}
